package startup;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import zzw.unicliinterfaces.CommentBlogInterface;
import zzw.unicliinterfaces.DeleteBlogInterface;
import zzw.unicliinterfaces.FavourBlogInterface;
import zzw.unicliinterfaces.ForwardBlogInterface;
import zzw.unicliinterfaces.GetTimeLinesInterface;
import zzw.unicliinterfaces.LoggedInUser;
import zzw.unicliinterfaces.LoginInterface;
import zzw.unicliinterfaces.PublishBlogInterface;
import zzw.unicliinterfaces.UniCliComment;
import zzw.unicliinterfaces.UniCliStatus;
import com.swtdesigner.ResourceManager;
public class UniCli {

	private BundleContext bundleContext=null;
	protected Shell shlUnicli;
	private Text text_userID;
	private Text text_password;
	
	private final static int NUM=20;
	private Composite[] cmps = new Composite[NUM];
	//private ScrolledComposite scrolledComposite;
	private int i=0;
	private Composite current=null;
	//这里要有个当前已登录的微博站点的用户名密码，当前用户
	//4个statuslist,一个当前的statuslist
	
	
	private List loggedInUserList = new ArrayList();
	
	//Properties props = System.get
	
	final StackLayout stackLayout = new StackLayout();
	int pageCount = 0;
	private String blogSites="";
	private Text text_blog;

	/**
	 * Launch the application.
	 * @param args
	 */
	public UniCli(BundleContext bundleContext){
		this.bundleContext = bundleContext;
		blogSites = System.getProperty("UniCli.BlogSite");
		System.out.println("初始化，获得微博站点"+blogSites);
	}
	public boolean OpenWindow(){
		if(this.bundleContext==null){
			return false;
		}
		
		try {
			UniCli window = new UniCli(bundleContext);
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	public static void main(String[] args) {
		try {
			UniCli window = new UniCli(null);
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shlUnicli.open();
		shlUnicli.layout();
		while (!shlUnicli.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlUnicli = new Shell();
		shlUnicli.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				System.out.println("close");
			}
		});
		shlUnicli.setSize(407, 670);
		shlUnicli.setText("UniCli");
		
		final Composite composite_panel = new Composite(shlUnicli, SWT.NONE);
		composite_panel.setBounds(1, 1, 398, 641);
		composite_panel.setLayout(stackLayout);
		
		final Composite composite_login = new Composite(composite_panel, SWT.NONE);
		composite_login.setBounds(0, 0, 350, 300);
		
		final Composite composite_normal = new Composite(composite_panel, SWT.NONE);
		composite_normal.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent e) {
				System.out.println("normal focused");
			}
			@Override
			public void focusLost(FocusEvent e) {
				System.out.println("normal focus lost");
			}
		});
		composite_normal.setBounds(0, 10, 352, 388);
		
		Composite composite_top = new Composite(composite_normal, SWT.NONE);
		composite_top.setBounds(0, 0, 392, 76);
		
		Label lblTop = new Label(composite_top, SWT.NONE);
		lblTop.setAlignment(SWT.CENTER);
		lblTop.setBounds(239, 10, 138, 34);
		
		final CCombo combo_blogSite = new CCombo(composite_top, SWT.BORDER);
		combo_blogSite.setBounds(40, 10, 138, 34);
		
		Button button_public = new Button(composite_top, SWT.NONE);
		button_public.addSelectionListener(new SelectionAdapter() { //主页
			@Override
			public void widgetSelected(SelectionEvent e) {
				initNormal(1);
			}
		});
		button_public.setBounds(66, 50, 57, 29);
		button_public.setText("主页");
		
		Button button_friend = new Button(composite_top, SWT.NONE);
		button_friend.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				initNormal(2);
			}
		});
		button_friend.setBounds(129, 50, 57, 29);
		button_friend.setText("好友");
		
		Button button_favorite = new Button(composite_top, SWT.NONE);
		button_favorite.setEnabled(false);
		button_favorite.setBounds(192, 50, 57, 29);
		button_favorite.setText("收藏");
		
		Button button_myown = new Button(composite_top, SWT.NONE);
		button_myown.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				initNormal(3);
			}
		});
		button_myown.setBounds(255, 50, 88, 29);
		button_myown.setText("我的微博");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(composite_normal, SWT.H_SCROLL | SWT.V_SCROLL);
		scrolledComposite.setBounds(77, 76, 320, 385);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_blog = new Composite(scrolledComposite, SWT.NONE);
		//这里创建显示微博的composite中的内容
		FillLayout fl =new FillLayout(SWT.VERTICAL);
		fl.marginHeight = 0;
		fl.marginWidth = 0;
		fl.spacing = 0;
		composite_blog.setLayout(fl);
		for(int i=0;i<NUM;i++){
			cmps[i] = new Composite(composite_blog,SWT.NONE);
			//System.out.println(cmps[i].getSize());
			//cmps[i].setSize(400,150);
			cmps[i].setBounds(0, 0, 402, 100);
			//cmps[i].setBackground(shlUnicli.getDisplay().getSystemColor(SWT.COLOR_CYAN));
			//cmps[i].addMouseTrackListener(new MouseTrackListener());
			//System.out.println(cmps[i].getSize());
			//cmps[i].pack();
			//cmps[i].computeSize(300, 100);
			new Text(cmps[i],SWT.None).setBounds(0,0,0,150);
			//有一种更加简单的方法可以显示图片，通过设置Label的setImage方法显示图片.
			//Label label = new Label(shell, SWT.NONE);
			//label.setImage(new Image(Display.getDefault(), "c:/abc.gif"));
			//添加一个Image框，两个Label框.
			Label lbImage = new Label(cmps[i],SWT.NONE);
			lbImage.setBounds(3, 5, 50, 50);
			lbImage.setText("image");
			lbImage.setData("image");
			Label lbNickName = new Label(cmps[i],SWT.NONE);
			lbNickName.setBounds(55, 5, 280, 30);
			lbNickName.setText("nick name");
			lbNickName.setData("nickname");
			Label lbBlog = new Label(cmps[i],SWT.NONE|SWT.WRAP);
			lbBlog.setBounds(55, 40, 280, 110);
			lbBlog.setText("blog content");
			lbBlog.setData("blog");
			
			final Button b1=new Button(cmps[i],SWT.NONE);
			final Button b2=new Button(cmps[i],SWT.NONE);
			final Button b3=new Button(cmps[i],SWT.NONE);
			final Button b4=new Button(cmps[i],SWT.NONE);
			//b1 = new Button(cmps[i],SWT.NONE);
			b1.setBounds(337, 10, 44, 23);
			b1.setText("评论");
			b1.setVisible(false);
			b1.setEnabled(false);
			//b1.pack();
			//b2 = new Button(cmps[i],SWT.NONE);
			b2.setBounds(337, 40, 44, 23);
			b2.setText("收藏");
			b2.setVisible(false);
			//b2.pack();
			//b3 = new Button(cmps[i],SWT.NONE);
			b3.setBounds(337, 70, 44, 23);
			b3.setText("转发");
			b3.setVisible(false);
			b3.setEnabled(false);
			
			b4.setBounds(337, 100, 44, 23);
			b4.setText("删除");
			b4.setVisible(false);
			
			b1.addSelectionListener(new SelectionAdapter() { //评论
				@Override
				public void widgetSelected(SelectionEvent e) {
					Button b = (Button)e.widget;
					Composite c = b.getParent();
					LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);
					UniCliStatus status = (UniCliStatus)c.getData();
					ServiceReference[] sr = null;
					CommentBlogInterface commentService = null;
					UniCliComment cmt = null;
					try {
						sr = bundleContext.getServiceReferences(
								CommentBlogInterface.class.getName(),
								"(UniCli.BlogSite=*)");
						if (null != sr) {
							System.out.println("get commentService OK");
							for (int i = 0; i < sr.length; i++) {
								commentService = (CommentBlogInterface) bundleContext.getService(sr[i]);
							}

							if (commentService != null) {
								System.out.println(" commentService not null");
							}
							long id = status.getId();
							cmt = commentService.comment(user, "123456", String.valueOf(id));
							if(cmt != null){
								System.out.println("评论成功 "+id);
							}
							
						}
					}catch(Exception ex){
						ex.printStackTrace();
					}
					
				}
			});
			b2.addSelectionListener(new SelectionAdapter() { //收藏
				@Override
				public void widgetSelected(SelectionEvent e) {
					Button b = (Button)e.widget;
					Composite c = b.getParent();
					LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);
					UniCliStatus status = (UniCliStatus)c.getData();
					ServiceReference[] sr = null;
					FavourBlogInterface favoriteService = null;
					UniCliStatus statusRes = null;
					try {
						sr = bundleContext.getServiceReferences(
								FavourBlogInterface.class.getName(),
								"(UniCli.BlogSite=*)");
						if (null != sr) {
							System.out.println("get commentService OK");
							for (int i = 0; i < sr.length; i++) {
								favoriteService = (FavourBlogInterface) bundleContext.getService(sr[i]);
							}

							if (favoriteService != null) {
								System.out.println(" commentService not null");
							}
							long id = status.getId();
							statusRes = favoriteService.favorite(user, id);
							if(statusRes != null){
								System.out.println("收藏成功 "+id);
							}
							
						}
					}catch(Exception ex){
						ex.printStackTrace();
					}
				}
			});
			b3.addSelectionListener(new SelectionAdapter() {  //转发
				@Override
				public void widgetSelected(SelectionEvent e) {
					Button b = (Button)e.widget;
					Composite c = b.getParent();
					LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);
					UniCliStatus status = (UniCliStatus)c.getData();
					ServiceReference[] sr = null;
					ForwardBlogInterface repostService = null;
					UniCliStatus statusRes = null;
					try {
						sr = bundleContext.getServiceReferences(
								ForwardBlogInterface.class.getName(),
								"(UniCli.BlogSite=*)");
						if (null != sr) {
							System.out.println("get commentService OK");
							for (int i = 0; i < sr.length; i++) {
								repostService = (ForwardBlogInterface) bundleContext.getService(sr[i]);
							}

							if (repostService != null) {
								System.out.println(" repostService not null");
							}
							long id = status.getId();
							statusRes = repostService.repost(user, "repost", String.valueOf(id));
							if(statusRes != null){
								System.out.println("转发成功 "+id);
							}
							
						}
					}catch(Exception ex){
						ex.printStackTrace();
					}
				}
			});
			b4.addSelectionListener(new SelectionAdapter() { //删除
				@Override
				public void widgetSelected(SelectionEvent e) {
					Button b = (Button)e.widget;
					Composite c = b.getParent();
					LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);
					UniCliStatus status = (UniCliStatus)c.getData();
					ServiceReference[] sr = null;
					DeleteBlogInterface deleteService = null;
					UniCliStatus statusRes = null;
					try {
						sr = bundleContext.getServiceReferences(
								DeleteBlogInterface.class.getName(),
								"(UniCli.BlogSite=*)");
						if (null != sr) {
							System.out.println("get commentService OK");
							for (int i = 0; i < sr.length; i++) {
								deleteService = (DeleteBlogInterface) bundleContext.getService(sr[i]);
							}

							if (deleteService != null) {
								System.out.println(" commentService not null");
							}
							long id = status.getId();
							statusRes = deleteService.delete(user, id);
							if(statusRes != null){
								System.out.println("删除成功 "+id);
							}
							
						}
					}catch(Exception ex){
						ex.printStackTrace();
					}
				}
			});
			cmps[i].addMouseTrackListener(new MouseTrackAdapter() {
				public void mouseEnter(MouseEvent e) {
					ShowButtons(e);
					return;
				}
			});
			lbImage.addMouseTrackListener(new MouseTrackAdapter() {
				public void mouseEnter(MouseEvent e) {
					ShowButtons_Label(e);
					return;
				}
			});
			lbNickName.addMouseTrackListener(new MouseTrackAdapter() {
				public void mouseEnter(MouseEvent e) {
					ShowButtons_Label(e);
					return;
				}
			});
			lbBlog.addMouseTrackListener(new MouseTrackAdapter() {
				public void mouseEnter(MouseEvent e) {
					ShowButtons_Label(e);
					return;
				}
			});
			
			//cmps[i].setMinSize(cmps[i].computeSize(300, 100););
			//System.out.println(cmps[i].getSize());
			cmps[i].pack();
			//cmps[i].layout();
		}
		scrolledComposite.setContent(composite_blog);
		scrolledComposite.setMinSize(composite_blog.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		Composite composite_publish = new Composite(composite_normal, SWT.NONE);
		composite_publish.setBounds(0, 461, 392, 179);
		
		text_blog = new Text(composite_publish, SWT.BORDER | SWT.MULTI);
		text_blog.setBounds(80, 50, 302, 89);
		
		Button button_publish = new Button(composite_publish, SWT.NONE);
		button_publish.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//发布微博
				String content = text_blog.getText();
				LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);//这里得弄一个当前的已登录用户
				ServiceReference[] sr = null;
				PublishBlogInterface publishService = null;
				boolean ret = false;
				UniCliStatus status=null;
				try {
					sr = bundleContext.getServiceReferences(
							PublishBlogInterface.class.getName(),
							"(UniCli.BlogSite=*)");
					if (null != sr) {
						System.out.println("get GetTimeLineInterface OK");
						for (int i = 0; i < sr.length; i++) {
							publishService = (PublishBlogInterface) bundleContext.getService(sr[i]);
						}

						if (publishService != null) {
							System.out.println("登录按钮 loginService not null");
						}

						status = publishService.publish(user, content);
					}
				}catch(Exception ee){
					ee.printStackTrace();
				}
			}
		});
		button_publish.setBounds(294, 145, 88, 29);
		button_publish.setText("发布微博");
		
		Label lblImage = new Label(composite_publish, SWT.NONE);
		lblImage.setImage(ResourceManager.getPluginImage("StartUp", "icons/1.jpg"));
		lblImage.setBounds(10, 53, 50, 50);
		//lblImage.setText("image");
		
		Label label_2 = new Label(composite_publish, SWT.NONE);
		label_2.setBounds(80, 10, 302, 34);

		
		stackLayout.topControl = composite_login;
		
		Label lblHelloWorld = new Label(composite_login, SWT.NONE);
		lblHelloWorld.setLocation(113, 49);
		lblHelloWorld.setSize(59, 19);
		lblHelloWorld.setText("微博网站");
		
		final CCombo combo = new CCombo(composite_login, SWT.BORDER);
		combo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("xia la "+combo.getText());
			}
		});
		combo.setBounds(113, 74, 151, 36);
		//System.out.println(blogSites);
		//combo.add("");
		if (blogSites != null) {
			String[] sites = blogSites.split(";");
			for (int i = 0; i < sites.length; i++) {
				System.out.println("one site= " + sites[i]);
				String[] oneSite = sites[i].split("=");
				System.out.println("site = " + oneSite[0] + " data = "
						+ oneSite[1]);
				combo.add(oneSite[1]);
				combo.setData(oneSite[1], oneSite[0]);
			}
		}
		//combo.add(blogSites);
		combo.select(1);
		
		Label label = new Label(composite_login, SWT.NONE);
		label.setBounds(113, 129, 53, 23);
		label.setText("帐号");
		
		text_userID = new Text(composite_login, SWT.BORDER);
		text_userID.setBounds(113, 151, 151, 36);
		text_userID.setText("zzw719196@126.com");
		
		Label label_1 = new Label(composite_login, SWT.NONE);
		label_1.setBounds(113, 207, 53, 23);
		label_1.setText("密码");
		
		text_password = new Text(composite_login, SWT.BORDER);
		text_password.setBounds(113, 227, 151, 36);
		text_password.setText("931318");
		
		Button button = new Button(composite_login, SWT.CHECK);
		button.setBounds(113, 279, 88, 29);
		button.setText("记住密码");
		
		Button button_1 = new Button(composite_login, SWT.CHECK);
		button_1.setBounds(113, 314, 88, 29);
		button_1.setText("自动登录");
		
		Button button_2 = new Button(composite_login, SWT.NONE);
		
		button_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				System.out.println("login button pressed");
				//VerifyCredentials vc = new VerifyCredentials();
				String blogSite = combo.getText();
				String userID   = text_userID.getText();
				String siteData = (String)combo.getData(blogSite);
				String password = text_password.getText();
				System.out.println("site="+blogSite+" user= "+userID +" password= "+password);
				if(blogSite.equals("") || userID.equals("") || password.equals("")){
					MessageDialog.openError(shlUnicli, "登录","请输入登录信息！");
					return;
				}
				ServiceReference[] sr=null;
				LoginInterface loginService=null;
				boolean ret=false;
				try{
					sr = bundleContext.getServiceReferences(LoginInterface.class.getName(),"(UniCli.BlogSite=*)");
					}
				catch(Exception ise){
					ise.printStackTrace();
				}
				if(null != sr){
					System.out.println("sr not null");
					for(int i=0;i<sr.length;i++){
						loginService = (LoginInterface)bundleContext.getService(sr[i]);
					}
					
					if(loginService != null){
						System.out.println("登录按钮 loginService not null");
					}
					try{
					    ret = loginService.login(siteData,userID, password, false);
					    if(ret){
					    	System.out.println("log in OK");
					    	//切换到第二个页面
					    	LoggedInUser u = new LoggedInUser();
					    	u.blogSite = siteData;
					    	u.blogName = combo.getText();
					    	u.userID = userID;
					    	u.password = password;
					    	//这里要判断一下list里是否已经有了这个登录用户
					    	loggedInUserList.add(u);
					    	combo_blogSite.removeAll();
					    	for(Object o:loggedInUserList){
					    		combo_blogSite.add(((LoggedInUser)o).blogName);
					    	}
					    	initNormal(1);//第一次进入到normal界面时的初始化
					    	stackLayout.topControl = composite_normal;
							composite_panel.layout();
					    }
					    else{
					    	System.out.println("log in failed  fffff");
					    	MessageDialog.openError(shlUnicli, "登录失败", "登录失败，输入的用户名或密码错误，请核对微博网站和对应的用户名");
					    }
					}catch(Exception excp){
						System.out.println("log in failed");
						excp.printStackTrace();
					}
				}
			}
//				ServiceReference[] sr=null;
//				LoginInterface loginService=null;
//				try{
//					sr = bundleContext.getServiceReferences(LoginInterface.class.getName(),"(UniCli.BlogSite=*)");
//					}catch(Exception ise){
//					ise.printStackTrace();
//				}
//				
//				//bundleContext.get
//				if(null != sr){
//					System.out.println("sr not null");
//					for(int i=0;i<sr.length;i++){
//						loginService = (LoginInterface)bundleContext.getService(sr[i]);
//					}
//					
//					if(loginService != null){
//						System.out.println("loginService not null");
//					}
//					try{
//					    loginService.login("SinaWeibo","zzw719196@126.com", "931318", false);
//					}catch(Exception excp){
//						excp.printStackTrace();
//					}
//				}
//				
//			}
		});
		button_2.setBounds(131, 360, 102, 42);
		button_2.setText("登录");
		
		Button button_3 = new Button(composite_login, SWT.NONE);
		
		button_3.setBounds(125, 471, 88, 29);
		button_3.setVisible(false);
		button_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				pageCount = (++pageCount) % 2;
				stackLayout.topControl = pageCount==0 ? composite_login : composite_normal;
				composite_panel.layout();
			}
		});
		button_3.setText("New Button");
		composite_panel.layout();
		
	}
	
	private int clearComposite(){
		for(int i=0;i<NUM;i++){
			Control[] ctr = cmps[i].getChildren();
			for(int j=0;j<ctr.length;j++){
				if(ctr[j] instanceof Label){
					Label l = (Label)ctr[j];
					if(ctr[j].getData().equals("image")){
						//label.setImage(new Image(Display.getDefault(), "c:/abc.gif"));
						l.setImage(null);
					}
					if (ctr[j].getData().equals("nickname")) {
						l.setText("");
						
					}
					if (ctr[j].getData().equals("blog")) {
						l.setText("");
						//l.pack();//不行啊
					}
					
				}
			}
		}
		return 0;
	}

	private int initNormal(int type) {
		// 从LoggedInUser获得第一个微博站点，获取用户在这个站点的public time line
		LoggedInUser user = (LoggedInUser) loggedInUserList.get(0);
		ServiceReference[] sr = null;
		GetTimeLinesInterface getTimeLineService = null;
		boolean ret = false;
		List<UniCliStatus> sl=null;
		clearComposite();
		
		try {
			sr = bundleContext.getServiceReferences(
					GetTimeLinesInterface.class.getName(),
					"(UniCli.BlogSite=*)");
			if (null != sr) {
				System.out.println("get GetTimeLineInterface OK");
				for (int i = 0; i < sr.length; i++) {
					getTimeLineService = (GetTimeLinesInterface) bundleContext.getService(sr[i]);
				}

				if (getTimeLineService != null) {
					System.out.println("登录按钮 loginService not null");
				}

				sl = getTimeLineService.GetTimeLines(user, type);
				for (UniCliStatus s : sl) {
					System.out.println(s);
				}
			}
		
		if(sl!=null){
			//把微博信息显示到界面上
			//Clear cmps[] //把之前的内容清空
			for(int i=0;i<NUM;i++){
				if(i>=sl.size()){
					break;
				}
				UniCliStatus s = sl.get(i);
				if(s==null){
					break;
				}
				cmps[i].setData(s);
				Control[] ctr = cmps[i].getChildren();
				for(int j=0;j<ctr.length;j++){
					if(ctr[j] instanceof Label){
						Label l = (Label)ctr[j];
						if(ctr[j].getData().equals("image")){
							//label.setImage(new Image(Display.getDefault(), "c:/abc.gif"));
							URL url = new URL(s.getUser().getProfileImageUrl());
							ImageDescriptor imd = ImageDescriptor.createFromURL(url);
							l.setImage(imd.createImage());
						}
						if (ctr[j].getData().equals("nickname")) {
							l.setText(s.getUser().getName()+s.getCreatedAt());
							//System.out.println("getsource: "+s.getSource());
						}
						if (ctr[j].getData().equals("blog")) {
							l.setText(s.getText());
							//l.pack();//不行啊
						}
						
					}
				}
			}
			for(UniCliStatus s:sl){
				//
			}
		}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return 0;
	}
	
	public void ShowButtons(MouseEvent e){
		Composite c = (Composite) e.widget;
		if (current == null) {
			current = c;
		} else {
			if (current != c) {
				Control[] ctr = current.getChildren();
				for (int i = 0; i < ctr.length; i++) {
					if (ctr[i] instanceof Button) {
						// System.out.println("Button   exit");
						ctr[i].setVisible(false);
						// ctr[i].setEnabled(false);
						// ctr[i].pack();
					}
				}
				current = c;
			}
		}

		Control[] ctr = c.getChildren();
		for (int i = 0; i < ctr.length; i++) {
			if (ctr[i] instanceof Button) {

				ctr[i].setVisible(true);
			}
		}

	}
	public void ShowButtons_Label(MouseEvent e){
		Composite c = ((Label) e.widget).getParent();
		if (current == null) {
			current = c;
		} else {
			if (current != c) {
				Control[] ctr = current.getChildren();
				for (int i = 0; i < ctr.length; i++) {
					if (ctr[i] instanceof Button) {
						// System.out.println("Button   exit");
						ctr[i].setVisible(false);
						// ctr[i].setEnabled(false);
						// ctr[i].pack();
					}
				}
				current = c;
			}
		}

		Control[] ctr = c.getChildren();
		for (int i = 0; i < ctr.length; i++) {
			if (ctr[i] instanceof Button) {

				ctr[i].setVisible(true);
			}
		}

	}
	public void HideButtons(MouseEvent e){
		if(current!=null){
			Control[] ctr = current.getChildren();
			for (int i = 0; i < ctr.length; i++) {
				if (ctr[i] instanceof Button) {
					// System.out.println("Button   exit");
					ctr[i].setVisible(false);
					//ctr[i].setEnabled(false);
					// ctr[i].pack();
				}
			}
			current = null;
		}
	}
}
